<template>
<div>
    <div class="box-mid">
        <el-button type="primary" v-hasPermission="'project:operate'" @click="$emit('add', true)">新增</el-button>
    </div>
    <div class="box-table">
        <el-table :data="tableData.rows" tooltip-effect="dark" v-loading="tableData.loading">
            <template slot="empty">
                <no-data :types="tableData.isSearch">
                    <span>暂无数据</span>
                </no-data>
            </template>
            <el-table-column prop="projectName" label="项目名称" show-overflow-tooltip></el-table-column>
            <el-table-column prop="projectCode" label="项目代码" show-overflow-tooltip></el-table-column>
            <el-table-column prop="ownerUserName" label="项目所有者" show-overflow-tooltip></el-table-column>
            <el-table-column prop="createTime" label="创建时间" show-overflow-tooltip></el-table-column>
            <el-table-column label="操作">
                <template slot-scope="scope">
                    <el-button v-hasPermission="'project:operate'" :disabled="!scope.row.isOwner" type="text" @click="$router.push(`/projectSet/${scope.row.projectId}`)">修改</el-button>
                    <el-button v-hasPermission="'project:operate'" @click="handleToExp(scope.row.projectId)" type="text">进入机器学习</el-button>
                </template>
            </el-table-column>
        </el-table>
    </div>
    <div class="box-pagenation" v-if="tableData.rows.length>0">
        <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="tableData.currentPage" :page-size="tableData.pageSize" layout="total, sizes, prev, pager, next, jumper" :total="tableData.total">
        </el-pagination>
    </div>
</div>
</template>

<script>
import NoData from '@/components/NoData'
export default {
    name: 'ProjectsTable',
    components: { NoData },
    props: {
        tableData: {
            type: Object,
            required: true
        }
    },
    methods: {
        handleToExp (id) {
            localStorage.setItem('projectId', id)
            window.open(`${location.origin}/exp/index.html`)
        },
        handleCurrentChange (val) {
            this.tableData.currentPage = val
            this.$emit('flash')
        },
        handleSizeChange (val) {
            this.tableData.pageSize = val
            this.$emit('flash')
        }
    }
}
</script>
